import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/app_permission/yt_tab_view_model.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/pages/alarm/alarm_home/alarm_home_view.dart';
import 'package:yt_devops/pages/tasks/create_repair_task/repair_task_operate_enum.dart';
import 'package:yt_devops/pages/tasks/task_list/task_list_view.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/routers/router_path.dart';
import 'package:yt_devops/utils/constants/permission_page_constant.dart';
import 'package:yt_devops/utils/func_utils.dart';

class OperationMatainanceController extends GetxController
    with GetTickerProviderStateMixin {
  TabController? tabController;

  List<String> get conditions => [
        if (FuncUtils.isPassAuthority(
            [PermissionConstant.operationWorkOrderInstall]))
          ResKey.workOrderInstall.tr,
        if (FuncUtils.isPassAuthority(
            [PermissionConstant.operationWorkOrderMaintenance]))
          ResKey.workOrderMaintenance.tr
      ];

  List<YtTabViewModel> tabWidgetList = [
    YtTabViewModel(
      imageString: '',
      permissionString: PermissionConstant.operationAlarm,
      labelString: ResKey.alarm,
      permissionWidget: AlarmHomePage(),
    ),
    YtTabViewModel(
      imageString: '',
      permissionString: PermissionConstant.operationWorkOrder,
      labelString: ResKey.task,
      permissionWidget: TaskListPage(),
    )
  ];
  @override
  void onInit() {
    super.onInit();
  }

  @override
  void onReady() {}
  initData() {}

  @override
  void onClose() {}
  addHandler(BuildContext context) {
    int selectedIndex = -1;
    showDialog(
        context: context,
        builder: (_) => StatefulBuilder(
              builder: (context, state) {
                return BrnSingleSelectDialogWidget(
                    isClose: true,
                    title: ResKey.pleSelectedCreateOrderType.tr,
                    conditions: conditions,
                    checkedItem:
                        selectedIndex == -1 ? null : conditions[selectedIndex],
                    submitText: ResKey.sure.tr,
                    isCustomFollowScroll: true,
                    themeData: BrnDialogConfig(
                        dialogWidth: 300.w,
                        contentTextStyle: BrnTextStyle(fontSize: 16.sp)),
                    onItemClick: (BuildContext context, int index) {
                      selectedIndex = index;
                      state(() {});
                    },
                    onSubmitClick: (data) {
                      if (data == conditions[0]) {
                        toCreateInstall();
                      } else if (data == conditions[1]) {
                        toCreateRepair();
                      }
                    });
              },
            ));
  }

  // 去创建安装单
  toCreateInstall() {
    Get.toNamed(RouterPath.createInstallTask);
  }

  // 去创建维修单
  toCreateRepair() {
    Get.toNamed(RouterPath.createRepairTask,
        arguments: {'type': RepairTaskTypeOperateEnum.create});
  }
}
